<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能地址解析</title>
    <link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
    <style>
        body {
            font-family: sans-serif;
            margin: 20px;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .container {
            max-width: 800px;
            margin: 40px auto;
            padding: 30px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #007bff;
            margin-bottom: 30px;
        }
        textarea {
            width: 100%;
            min-height: 100px;
            padding: 10px;
            border: 1px solid #ced4da;
            border-radius: 4px;
            box-sizing: border-box; /* Include padding and border in element's total width and height */
            margin-bottom: 15px;
            font-size: 1rem;
        }
        button {
            display: block;
            width: 100%;
            padding: 12px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1.1rem;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #0056b3;
        }
        button:disabled {
            background-color: #6c757d;
            cursor: not-allowed;
            opacity: 0.7;
        }
        .spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255,255,255,.3);
            border-radius: 50%;
            border-top-color: #fff;
            animation: spin 1s ease-in-out infinite;
            margin-right: 8px;
            vertical-align: middle;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        .result-section {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        h2 {
            color: #555;
            margin-bottom: 15px;
        }
        pre {
            background-color: #e9ecef;
            padding: 15px;
            border-radius: 4px;
            white-space: pre-wrap; /* Wrap long lines */
            word-wrap: break-word; /* Break long words */
            font-family: monospace;
            font-size: 0.95rem;
            border: 1px solid #dee2e6;
        }
        .error {
            color: #dc3545;
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            padding: 10px 15px;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #495057;
        }
        .examples {
            font-size: 0.9rem;
            color: #666;
            margin-top: 10px;
        }
        .examples h3 {
            margin-bottom: 5px;
            font-size: 1rem;
            color: #555;
        }
        .examples ul {
            margin-top: 5px;
            padding-left: 20px;
        }
        .examples li {
            margin-bottom: 3px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>智能地址解析器</h1>

        {% if error %}
        <div class="error">
            <strong>错误：</strong> {{ error }}
        </div>
        {% endif %}

        <form method="post" id="addressForm" onsubmit="return handleSubmit()">
            <label for="address">请输入或粘贴地址信息：</label>
            <textarea id="address" name="address" rows="5" placeholder="例如：广东省深圳市南山区粤海街道科技南十二路 中科纳能大厦 A座 3楼 张三 13800138000 0755-12345678">{{ address_input or '' }}</textarea>
            <button type="submit" id="submitBtn">解析地址</button>
        </form>

        <div class="examples">
            <h3>支持的地址格式示例：</h3>
            <ul>
                <li>标准地址：广东省深圳市南山区粤海街道科技南十二路 中科纳能大厦 A座 3楼 张三 13800138000</li>
                <li>带固定电话：北京市朝阳区三里屯街道 某小区 10号楼 李四 13912345678 010-12345678</li>
                <li>带虚拟号码：广东省广州市海珠区赤岗街道测试专用，王五，14749871654-8722</li>
                <li>同时含手机和固话：广东省广州市天河区体育西路101号 王芳 020-38889999 13522223333</li>
            </ul>
        <div class="contact-info">
            <h3>接口调用请联系：</h3>
            <p><a href="mailto:example@example.com">example@example.com</a></p>
            <p><a href="{{ url_for('api_docs') }}">查看API接口文档</a></p>
        </div>
        </div>

        {% if result %}
        <div class="result-section">
            <h2>解析结果 (JSON):</h2>
            <pre>{{ result }}</pre>
        </div>
        {% endif %}
    </div>

    <script>
        function handleSubmit() {
            const form = document.getElementById('addressForm');
            const submitBtn = document.getElementById('submitBtn');
            const address = document.getElementById('address').value.trim();
            
            // 验证地址是否为空
            if (!address) {
                alert('请输入要解析的地址');
                return false;
            }
            
            // 禁用提交按钮并显示加载状态
            submitBtn.disabled = true;
            submitBtn.innerHTML = '<span class="spinner"></span>正在解析...';
            
            // 提交表单
            return true;
        }
        
        // 页面加载完成后，确保按钮处于启用状态
        document.addEventListener('DOMContentLoaded', function() {
            const submitBtn = document.getElementById('submitBtn');
            submitBtn.disabled = false;
            submitBtn.innerHTML = '解析地址';
        });
    </script>
</body>
</html> 